<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/jquery.min.js"></script>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <script src="../../layui/layui.js"></script>
    <link rel="stylesheet" href="../../layui/css/formSelects-v4.css">
    <script src="../../js/config.js"></script>
</head>
<body>
<h1>结算费用</h1>
<hr>
<form action="" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" id="rname" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">病单号</label>
            <div class="layui-input-inline">
                <input type="text" id="disoddid" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <input type="text" id="typeid" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">就诊时间</label>
            <div class="layui-input-inline">
                <input type="text" id="retime" autocomplete="off" class="layui-input">
            </div>
        </div>
        <button type="button" class="layui-btn" onclick="reloadData()" lay-submit="" lay-filter="demo1">查询</button>
    </div>
</form>

<table class="layui-hide" id="userList" lay-filter="userList"></table>


<script>
    var table ;
    function reloadData(){
        //执行重载
        table.reload('userList', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: {
                rname : $("#rname").val(),
                disoddid: $("#disoddid").val(),
                typeid: $("#typeid").val(),
                retime: $("#retime").val()
            }
        });
    }

    layui.use('form',function () {
        var form = layui.form;
    });
    layui.use(['table','form'], function(){
        table = layui.table;
        var form = layui.form;

        table.render({
            elem: '#userList'
            ,url:'http://localhost:8888/register/listss'
            ,page: true
            ,even : true
            ,toolbar: '#tool'
            ,id : "userList"
            ,cols: [[
                ,{field:'rid', title: '编号', sort: true}
                ,{field:'disoddid', title: '病单号'}
                ,{field:'rname', title:'患者姓名'}
                ,{field:'hisusers', title: '预约医生',templet:function (d) {
                        if (d.hisusers.length == 0) {
                            return "-";
                        }
                        let str = "";
                        for (let hisrole of d.hisusers) {
                            str += hisrole.username;
                        }
                        return str;
                    }}
                ,{field:'retime', title: '就诊时间'}
                ,{field:'fee', title: '挂号费'}
                ,{field:'registerTypes', title: '状态',templet:function (d) {
                        if (d.registerTypes.length == 0) {
                            return "-";
                        }
                        let str = "";
                        for (let hisrole of d.registerTypes) {
                            str += hisrole.typename;
                        }
                        return str;


                    }}
                ,{field:'customers', title: '余额' ,templet:function (d) {
                        if (d.customers.length == 0) {
                            return "-";
                        }
                        let str = "";
                        for (let hisrole of d.customers) {
                            str += hisrole.fee;
                        }
                        return str;
                    }}

                ,{fixed: 'right', title:'操作', toolbar: '#toolbarDemo'}
            ]]
        });
    });
</script>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="update"><i class="layui-icon layui-icon-upload-drag"></i>结账</button>
</div>
</script>
<script>
    var table ;
    layui.use(['form','table'],function(){
        table = layui.table;
        var form = layui.form;

        //头工具栏事件


        //监听行内的工具条
        table.on('tool(userList)',function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

            if (layEvent === 'update'){//TODO 编辑
                $.get('zhangdan.html',function (datas) {
                    layer.open({
                        title: '编辑',
                        type:1,
                        anim:4,
                        skin:'layui-layer-molv',
                        area:'1200px',
                        content:datas,
                        maxmin:true,
                        btn : ['结账','关闭'],
                        success:function(){
                            // layer.msg(data.customers[0].fee);
                           data.locked = data.locked ==0 ? null :data.locked;
                           data.id=data.rid;
                            form.val('updateForm',data);
                        },
                        yes : function () {
                            var str = $("#update_user_form").serialize();
                            $.post(`${new Config().base_url}/register/updates`,str,function (data) {
                                layer.close(layer.index);
                                table.reload('userList');
                            });
                        }
                    });
                });
            }
        });
    });
</script>
</body>
</html>